package eighteenthDay;


import java.util.ArrayList;
import java.util.List;

public class BSTIterator {
    private int next = 0;
    private List<Integer> ans;
    public BSTIterator(TreeNode root) {
        ans = new ArrayList<>();
        inorder(root);
    }

    public int next() {
        int index = ans.get(next++);
        return index;
    }

    public boolean hasNext() {
        if (next < ans.size()){
            return true;
        }
        return false;
    }
    public void inorder(TreeNode node) {
        if (node == null){
            return;
        }
        inorder(node.left);
        ans.add(node.val);
        System.out.println("------------");
        System.out.println(node.val);
        inorder(node.right);
    }
}
